package com.op.controller;

import com.op.model.req.ExamPaperReq;
import com.op.model.req.SubmitPaperReq;
import com.op.model.vo.ExamPaperVo;
import com.op.response.ResponseResult;
import com.op.service.PaperService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName： PaperController
 * Date： 2021/10/18 14:38
 *
 * @author 孤焰
 * @version 1.0
 **/

@RestController
@RequestMapping("/paper")
public class PaperController {
    /**
     * 服务对象
     */
    @Resource
    private PaperService paperService;

    /**
     * 组卷接口（根据入参的questionBank、tags、difficult组卷）
     * @param examPaperReq 组卷入参
     * @return 题目列表
     */
    @PostMapping("/examPaper")
    public ResponseResult<List<ExamPaperVo>> examPaper(ExamPaperReq examPaperReq) {
        return ResponseResult.success(paperService.examPaper(examPaperReq));
    }

    /**
     * 交卷接口（计算题目统计数值并对数据库修改，最后返回一个此次答题评分）
     * @param submitPaperReq 交卷入参
     * @return 交卷结果
     */
    @PutMapping("/submitPaper")
    public ResponseResult<Boolean> submitPaper(@RequestBody SubmitPaperReq submitPaperReq) {
        // 如果临时用户交卷，则数据库不记录答题数据
        if (submitPaperReq.getUserId() == null) {
            return ResponseResult.success();
        }
        return ResponseResult.success(paperService.submitPaper(submitPaperReq.getPaperDataList(), submitPaperReq.getUserId()));
    }

}
